1 | <!DOCTYPE html>
|
2 | <html lang="en">
|
3 | <head>
|
4 | <meta charset="utf-8">
|
5 | <title>JSDoc: Tutorial: Changes API</title>
|
6 |
|
7 | <script src="scripts/prettify/prettify.js"> </script>
|
8 | <script src="scripts/prettify/lang-css.js"> </script>
|
9 | |
10 |
|
11 |
|
12 | <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
|
13 | <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
|
14 | </head>
|
15 |
|
16 | <body>
|
17 |
|
18 | <div id="main">
|
19 |
|
20 | <h1 class="page-title">Tutorial: Changes API</h1>
|
21 |
|
22 | <section>
|
23 |
|
24 | <header>
|
25 |
|
26 |
|
27 | <h2>Changes API</h2>
|
28 | </header>
|
29 |
|
30 | <article>
|
31 | <h1>Overview</h1><p>LokiJS 1.1 introduces a "Changes API" that enables the user to keep track of the changes happened to each collection since a particular point in time, which is usually the start of a work session but it could be a user defined one.
|
32 | This is particularly useful for remote synchronization.</p>
|
33 | <h2>Description of the Changes API</h2><p>The Changes API is a collection-level feature, hence you can establish which collections may simply contain volatile data and which ones need to keep a record of what has changed.</p>
|
34 | <p>The Changes API is an optional feature and can be activated/deactivated by either passing the option <code>{ disableChangesApi: isDisabled }</code> in the config parameter of a collection constructor, or by calling <code>collection.setChangesApi(isEnabled)</code>.
|
35 | Note that LokiJS will always set the fastest performing setting as default on a collection or database, hence the Changes API is <strong>disabled</strong> by default.</p>
|
36 | <p>There are three events which will trigger a Changes API operation: inserts, updates and deletes.
|
37 | When either of these events occur, on a collection with Changes API activated, the collection will store a snapshot of the relevant object, associated with the operation and the name of the collection.</p>
|
38 | <p>From the database object it is then possible to invoke the <code>serializeChanges</code> method which will generate a string representation of the changes occurred to be used for synchronization purposes.</p>
|
39 | <h2>Usage</h2><p>To enable the Changes API make sure to either instantiate a collection using <code>db.addCollection('users', { disableChangesApi: false })</code>, or call <code>users.setChangesApi(true)</code> (given an example <code>users</code> collection).</p>
|
40 | <p>To generate a string representation of the changes, call <code>db.serializeChanges()</code>. This will generate a representation of all the changes for those collections that have the Changes API enabled. If you are only interested in generating changes for a subset of collections, you can pass an array of names of the collections, i.e. <code>db.serializeChanges(['users']);</code>.</p>
|
41 | <p>To clear all the changes, call <code>db.clearChanges()</code>. Alternatively you can call <code>flushChanges()</code> on the single collection, normally you would call <code>db.clearChanges()</code> on a callback from a successful synchronization operation.</p>
|
42 | <p>Each change is an object with three properties: <code>name</code> is the collection name, <code>obj</code> is the string representation of the object and <code>operation</code> is a character representing the operation ("I" for insert, "U" for update, "R" for remove). So for example, inserting user <code>{ name: 'joe' }</code> in the users collection would generate a change <code>{ name: 'users', obj: { name: 'joe' }, operation: 'I' }</code>. Changes are kept in order of how the happened so a 3rd party application will be able to operate insert updates and deletes in the correct order.</p>
|
43 | </article>
|
44 |
|
45 | </section>
|
46 |
|
47 | </div>
|
48 |
|
49 | <nav>
|
50 | <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Collection.html">Collection</a></li><li><a href="DynamicView.html">DynamicView</a></li><li><a href="Loki.html">Loki</a></li><li><a href="LokiEventEmitter.html">LokiEventEmitter</a></li><li><a href="LokiFsAdapter.html">LokiFsAdapter</a></li><li><a href="LokiFsStructuredAdapter.html">LokiFsStructuredAdapter</a></li><li><a href="LokiIndexedAdapter.html">LokiIndexedAdapter</a></li><li><a href="LokiLocalStorageAdapter.html">LokiLocalStorageAdapter</a></li><li><a href="LokiMemoryAdapter.html">LokiMemoryAdapter</a></li><li><a href="LokiPartitioningAdapter.html">LokiPartitioningAdapter</a></li><li><a href="Resultset.html">Resultset</a></li></ul><h3>Tutorials</h3><ul><li><a href="tutorial-Autoupdating Collections.html">Autoupdating Collections</a></li><li><a href="tutorial-Changes API.html">Changes API</a></li><li><a href="tutorial-Collection Transforms.html">Collection Transforms</a></li><li><a href="tutorial-Indexing and Query performance.html">Indexing and Query performance</a></li><li><a href="tutorial-Loki Angular.html">Loki Angular</a></li><li><a href="tutorial-Persistence Adapters.html">Persistence Adapters</a></li><li><a href="tutorial-Query Examples.html">Query Examples</a></li></ul>
|
51 | </nav>
|
52 |
|
53 | <br class="clear">
|
54 |
|
55 | <footer>
|
56 | Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Sun Dec 18 2016 19:39:52 GMT-0500 (Eastern Standard Time)
|
57 | </footer>
|
58 |
|
59 | <script> prettyPrint(); </script>
|
60 | <script src="scripts/linenumber.js"> </script>
|
61 | </body>
|
62 | </html> |
\ | No newline at end of file |